package com.example.bookappgraduation;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class BookReaderActivity extends AppCompatActivity {

    private TextView textViewBookContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_reader);

        textViewBookContent = findViewById(R.id.textViewBookContent);

        String bookTitle = getIntent().getStringExtra("book_title");
        String bookContent = getIntent().getStringExtra("book_content");//从Intent中获取String类型 键名为book_content的值

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle(bookTitle != null ? bookTitle : "阅读");
        }

        if (bookContent != null) {
            textViewBookContent.setText(bookContent);
        } else {
            textViewBookContent.setText("没有可阅读的内容。");
        }
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish(); // 返回上一页
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}